package com.tgpms.web.assets.controller;

import com.alibaba.fastjson.JSONObject;
import com.tgpms.common.Result;
import com.tgpms.interfaces.dto.VformInterface;
import com.tgpms.util.Common;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.io.UnsupportedEncodingException;
import java.util.HashMap;
import java.util.Map;

/**
 * @author newway
 * <p>
 * 固定资产盘点接口
 */
@Api(value = "ValueListController", tags = "值列表接口")
@RestController
@RequestMapping(value = "/ev/valuelist")
public class ValueListController {

    @Resource
    private VformInterface vformInterface;

    /**
     * 14. VForm 第十三个接口： 值列表查询接口 操作
     *
     * @param params
     * @return
     */
    @ApiOperation(value = "VForm 第十三个接口： 值列表查询接口 操作", notes = "VForm 第十三个接口： 值列表查询接口 操作", httpMethod = "POST")
    @PostMapping(value = "/getLov")
    public Result getLov(@RequestParam(value = "itemname", required = true) String itemname,
                         @RequestParam(value = "datas", required = true) String datas,
                         @RequestParam(value = "params", required = false) String params,
                         @RequestParam(value = "dataownermode", required = false) String dataownermode,
                         @RequestParam(value = "dataowner", required = false) String dataowner
                         ) {

        Result result = null;
        try {
            result = vformInterface.getLov(itemname,datas,params,dataownermode,dataowner);
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        return result;
    }

    /**
     * 14. VForm 第十三个接口： 值列表查询接口 操作
     *
     * @param params
     * @return
     */
    @ApiOperation(value = "VForm 第十四个接口： 值列表分页查询接口 操作", notes = "VForm 第十四个接口： 值列表分页查询接口 操作", httpMethod = "POST")
    @PostMapping(value = "/getLovPage")
    public Result getLovPage(@RequestParam(value = "itemname", required = true) String itemname,
                         @RequestParam(value = "datas", required = true) String datas,
                         @RequestParam(value = "params", required = false) String params,
                         @RequestParam(value = "dataownermode", required = false) String dataownermode,
                         @RequestParam(value = "dataowner", required = false) String dataowner,
                         @RequestParam(value = "pageNo", required = false) String pageNo,
                         @RequestParam(value = "pageSize", required = false) String pageSize
    ) {

        Result result = null;
        result = vformInterface.getLovPage(itemname,datas,pageNo,pageSize,params,dataownermode,dataowner);
        return result;
    }
    
    @ApiOperation(value = "VForm 12.1接口： 特殊sql查询接口 操作", notes = "VForm 12.1接口： 特殊sql查询接口 操作", httpMethod = "POST")
    @PostMapping(value = "/specialSQL")
    public Result specialSQL(@RequestParam(value = "code", required = true) String code,
    		@RequestParam(value = "page", required = true) String page,
    		@RequestParam(value = "size", required = true) String size) {
    	Result result = null;
        try {
        	JSONObject json = new JSONObject();
        	json.put("[SQL1]", ",E4.FULL_NAME AS checkBy4Name");
        	json.put("[SQL2]", " LEFT JOIN ENTITIES E4 ON E4.ENTITY_ITEM = t.CHECK_BY3");
        	json.put("[SQL3]", " ");
        	
        	
        	
        	System.out.println("上送参数为:"+json.toJSONString());
        	result = vformInterface.multiForMsQueryBySql(code, json.toJSONString(),page, size, "Y", null, null);
        } catch (Exception e) {
            e.printStackTrace();
        }
		return result;
    }
    
}
